package cn.demengsite.service.impl;

import cn.demengsite.dao.MemberDAO;
import cn.demengsite.dao.OrderDAO;
import cn.demengsite.dao.ReportDAO;
import cn.demengsite.model.BaseInfo;
import cn.demengsite.model.Order;
import cn.demengsite.model.Report;
import cn.demengsite.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportDAO reportDAO;

    @Autowired
    private OrderDAO orderDAO;

    @Autowired
    private MemberDAO memberDAO;


    @Override
    public BaseInfo getSaleReport(String dateTime) {
        BaseInfo baseInfo ;
        List<Report> reportList =reportDAO.getSaleReport(dateTime);

        return new BaseInfo("0","查询成功",reportList);
    }

    @Override
    public BaseInfo getSaleReportWithBeginEnd(String beginDate, String endDate) {
        return new BaseInfo("0","成功", reportDAO.getSaleReportWithBeginEnd(beginDate, endDate));
    }

    @Override
    public BaseInfo contactMember(Integer memberId, Integer orderId) {
        //先更新表order,绑定memberId
        orderDAO.contactMember(memberId,orderId);
        //获取到订单的总价格
        Order order =orderDAO.getOrderById(orderId);
        //总价格转换成积分
        memberDAO.memberGainScores(order.getTotalPrice(),memberId);
        return new BaseInfo("0","关联成功");
    }
}
